package com.imay.live.adapter;

import android.content.Context;
import android.widget.ImageView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.R;
import com.imay.live.helper.LevelHelper;
import com.imay.live.model.FeedSuggestModel;
import com.imay.live.model.UserModel;
import com.imay.live.utils.GlideUtil;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by chan on 2017/4/17.
 */
public class RepostAdapter extends BaseQuickAdapter<Object, BaseViewHolder> {

    private List<Object> datas = new ArrayList<>();

    public RepostAdapter() {
        super(R.layout.item_dynamics_label);
    }

    @Override
    protected void convert(BaseViewHolder helper, Object item) {
        Context context = helper.getConvertView().getContext();
        if (item instanceof UserModel) {
            UserModel user = (UserModel) item;
            helper.setText(R.id.tv_dynamics_label_text, context.getString(R.string.str_dynamics_at_text, user.getNick()));
            int icon = LevelHelper.getVIPIcon(user.getVip());
            helper.setImageResource(R.id.iv_vip, icon);
            helper.setVisible(R.id.tv_dynamics_tie_text, false);
            helper.setVisible(R.id.rl_dynamics_content_img, true);
            GlideUtil.loadCircleImage((ImageView) helper.getView(R.id.civ_item_content_img), user.getImgHead(), R.mipmap.pnl_00_head108);
        } else if (item instanceof FeedSuggestModel) {
            FeedSuggestModel label = (FeedSuggestModel) item;
            helper.setText(R.id.tv_dynamics_label_text, context.getString(R.string.str_dynamics_jin_text, label.getContent()));
            helper.setVisible(R.id.tv_dynamics_tie_text, true);
            helper.setVisible(R.id.rl_dynamics_content_img, false);
            helper.setText(R.id.tv_dynamics_tie_text, context.getString(R.string.str_dynamics_tie_text, label.getCount()));
        }
        helper.addOnClickListener(R.id.rl_dynamics_item_repost);
    }


    public void setUserModels(List<UserModel> userModels) {
        datas.clear();
        datas.addAll(userModels);
        super.setNewData(datas);
    }

    public void setLabelModels(List<FeedSuggestModel> labelModels) {
        datas.clear();
        datas.addAll(labelModels);
        super.setNewData(datas);
    }
}
